'use strict';

const { Controller } = require('egg');
class BaseController extends Controller {
  get token() {
    return this.ctx.request.header.authorization;
  }

  success(data) {
    this.ctx.body = {
      success: true,
      code: 20000,
      data,
    };
  }

  fail(message) {
    this.ctx.body = {
      success: false,
      code: 50000,
      message,
    };
  }

  notFound(msg) {
    msg = msg || 'not found';
    this.ctx.throw(404, msg);
  }
}
module.exports = BaseController;
